import { createRouter, createWebHistory } from "vue-router";

const staticRoutes = [
    {
    path: "/",
    redirect: "/Intelligent", // 🌟 添加这一项实现重定向
  },
  {
    path: "/Intelligent",
    name: "Intelligent",
    component: () => import("../views/history/index.vue"),
  },
  {
    path: "/404",
    name: "404",
    component: () => import("../views/error/404.vue"),
  },
];

const router = createRouter({
  history: createWebHistory("/test2/"),
  routes: staticRoutes,
});
// 路由前置守卫
router.beforeEach((to, from, next) => {
  const matched = router.getRoutes().find((route) => route.path === to.path);
  if (!matched && to.path !== "/404") {
    next({ name: "404" }); // 如果没有匹配到路由，跳转到 404
  } else {
    next(); // 正常跳转
  }
});
export default router;
